<?php

namespace App\Controller\Admin\System;

use App\Controller\Admin\AdminController;
use App\Controller\Admin\BaseController;
use App\Dao\System\SystemRolesDao;
use App\Dao\System\SystemRolesMenuDao;
use Hyperf\Di\Annotation\Inject;
use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\FormData;
use Yj\Apidog\Annotation\PostApi;
use Yj\Form\Elm;

/**
 * @ApiController(prefix="admin/system/roles")
 */
class SystemRolesController extends BaseController
{
    /**
     * @Inject()
     * @var SystemRolesDao
     */
    protected $systemRolesDao;

    /**
     * @PostApi(path="lists")
     * @return void
     */
    public function lists()
    {
        $params = $this->getValidatorData();
        $data = $this->systemRolesDao->lists($params);
        _SUCCESS($data);
    }


    /**
     * @PostApi(path="add",description="添加角色")
     * @FormData(key="name",rule="required")
     */
    public function add()
    {
        $params = $this->getValidatorData();
        $this->systemRolesDao->add($params);
        _SUCCESS();
    }

    /**
     * @PostApi(path="edit",description="添加角色")
     * @FormData(key="name",rule="required")
     * @FormData(key="id",rule="required")
     */
    public function edit()
    {
        $params = $this->getParams();
        $this->systemRolesDao->edit($params->only('id'), $params->except('id'));
        _SUCCESS();
    }

    /**
     * @Inject()
     * @var SystemRolesMenuDao
     */
    protected $systemRolesMenuDao;

    /**
     * @PostApi(path="set-menus",description="设置角色菜单权限")
     * @FormData(key="roles_id",rule="required")
     * @FormData(key="menus_id",rule="required")
     */
    public function setMenus()
    {
        $params = $this->getValidatorData();
        $this->systemRolesMenuDao->setMenus($params->get('roles_id'), $params->get('menus_id'));
        _GetLastSql();
        _SUCCESS();
    }

    /**
     * @PostApi(path="del",description="删除角色")
     * @FormData(key="id",rule="required")
     */
    public function del()
    {
        $roles_id = $this->getValidatorData('id');
        $this->systemRolesDao->del($roles_id);
        _SUCCESS();
    }

}